package com.platform.analysis.enums;

import com.platform.comm.constants.EnumOption;
import com.platform.comm.enums.IEnumOption;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author liujizheng
 * @version 1.0
 * @ClassName TableJoinType
 * @Description 表连接方式
 * @date 2021/9/17 17:38
 */
@EnumOption(name = "tableJoinType")
public enum TableJoinType implements IEnumOption<String> {
    /**
     * 左外连接
     */
    LEFT_OUTER_JOIN(" LEFT OUTER JOIN ", "左外连接"),
    /**
     * 内连接
     */
    INNER_JOIN(" INNER JOIN ", "内连接"),
    /**
     * 全连接
     */
    FULL_OUTER_JOIN(" FULL OUTER JOIN ", "全连接");

    String code;
    String title;
    TableJoinType(String code, String title) {
        this.code = code;
        this.title = title;
    }

    /**
     * 枚举项 “键”
     *
     * @return key 键
     */
    @Override
    public String key() {
        return name();
    }

    /**
     * 枚举项 “值”
     *
     * @return value 值
     */
    @Override
    public String value() {
        return title;
    }

    public String getCode() {
        return code;
    }

    /**
     * 枚举options
     *
     * @return 枚举项组成的map
     */
    @Override
    public Map<String, String> enums() {
        return Arrays.stream(values()).collect(Collectors.toMap(IEnumOption::key, IEnumOption::value));
    }

    public static TableJoinType parse(String name) {
        if (LEFT_OUTER_JOIN.name().equals(name)) {
            return LEFT_OUTER_JOIN;
        } else if (INNER_JOIN.name().equals(name)) {
            return INNER_JOIN;
        } else if (FULL_OUTER_JOIN.name().equals(name)) {
            return FULL_OUTER_JOIN;
        } else {
            return null;
        }
    }
}
